<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/content/variable.jsp"%>
<!DOCTYPE html>
<html lang="en" class="ie8 no-js">

<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <meta content="" name="description"/>
    <meta content="" name="author"/>
<%@ include file="/content/head.jsp"%>
</head>
<body>
<section class="content-header">
    <h1>
        系统管理
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>系统管理</a></li>
        <li><a href="#">数据字典</a></li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">数据字典信息</h3>
                </div>
                <div class="box-body">
                    <div class="table-scrollable">
                        <div id="toolbar" class="btn-group" style="padding-bottom:10px;">
                            <button id="btn_add" onclick="addInfo()" type="button" class="btn btn-default">
                                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                            </button>
                        </div>
                        <table class="table-striped table-hover table-bordered" id="dictionaryTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<%@ include file="/content/js.jsp"%>
</body>
<script>
    $(function () {
        init();
    });

    function init() {
        $('#dictionaryTable').bootstrapTable({
            //请求方法
            method: 'get',
            //是否显示行间隔色
            striped: true,
            //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            cache: false,
            //是否显示分页（*）
            pagination: true,
            //是否启用排序
            sortable: false,

            //每页的记录行数（*）
            pageSize: 10,
            //可供选择的每页的行数（*）
            pageList: [10, 25, 50, 100],
            url: "<%= path%>/dictionary/index_json",
            detailView: true,//父子表
            sidePagination: "server",
            //是否显示搜索
            search: false,
            //Enable the strict search.
            strictSearch: false,
            rowStyle: function (row, index) {
                return rowStyle(row, index);
            },
            idField: "dicId",
            columns: [{
                field: 'dicId',
                title: '字典编号',
                align: 'center',
                width: 100,
            },
                {
                    field: 'dictionaryName',
                    title: '字典名称',
                    align: 'center',
                },
                {
                    field: 'keyType',
                    title: '字段名称',
                    align: 'center',
                    width: 150
                },
                {
                    field: 'value',
                    title: '字段值',
                    align: 'center',
                    width: 150,
                },
                {
                    field: 'c',
                    title: '操作',
                    halign: 'center',
                    align: 'center',
                    width: 300,
                    formatter: function (value, row, rowIndex) {
                        return dicButtonFormatter(value, row, rowIndex);
                    }
                }],
            //注册加载子表的事件。注意下这里的三个参数！
            onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });

    }

    //初始化子表格
    function InitSubTable(index, row, $detail) {
        var parentid = row.dicId;
        var cur_table = $detail.html('<table></table>').find('table');
        $(cur_table).bootstrapTable({
            url: '<%= path%>/dictionary/children_json',
            method: 'get',
            queryParams: {parentId: parentid},
            ajaxOptions: {parentId: parentid},
            clickToSelect: true,
            sidePagination: "server",
            uniqueId: "dicId",
            pageSize: 10,
            pageList: [10, 25],
            columns: [{
                field: 'dicId',
                title: '字典编号',
                align: 'center',
                width: 100,
                },
                {
                    field: 'dictionaryName',
                    title: '字典名称',
                    align: 'center',
                },
                {
                    field: 'childName',
                    title: '字段名称',
                    align: 'center',
                    width: 150
                },
                {
                    field: 'value',
                    title: '字段值',
                    align: 'center',
                    width: 150,
                },
                {
                    field: 'c',
                    title: '操作',
                    halign: 'center',
                    align: 'center',
                    width: 300,
                    formatter: function (value, row, rowIndex) {
                        return dictionaryChildButtonFormatter(value, row, rowIndex);
                    }
                },],

        });
    };


    /**添加父菜单信息*/
    function addInfo() {
        modalOpen({
            id: "Form",
            title: '数据字典单信息',
            url: '<%= path%>/dictionary/add_plus',
            width: "700px",
            height: "650px",
        });
    }

    /**添加子菜单信息*/
    function addChild_obj(parentId) {
        modalOpen({
            id: "childForm",
            title: '数据字典单信息',
            url: '<%= path%>/dictionary/addChild_plus?parentId=' + parentId,
            width: "700px",
            height: "650px",
        });
    }
    /**修改父菜单信息*/
    function edit_obj(dicId) {
        modalOpen({
            id: "editForm",
            title: '修改数据字典信息',
            url: '${path}/dataDictionary/edit_plus?dicId=' + dicId,
            width: "700px",
            height: "550px",
        });
    }
    /**修改子菜单信息*/
    function editChild_obj(dicId) {
        modalOpen({
            id: "editChileForm",
            title: '修改子数据字典信息',
            url: '${path}/dataDictionary/editChild_plus?dicId=' + dicId,
            width: "700px",
            height: "550px",
        });
    }

    function status_obj(menuId, status) {
        modalConfirm("确认要更改状态吗？", function (bl) {
            if (bl) {
                $.post("${path}/menuInfo/statusInfo",
                    {'menuId': menuId, 'status': status}
                    , function (data) {
                        if (data.code == 9001) {
                            modalMsg("状态更改成功！", "success");
                            $('#menuTable').bootstrapTable('refresh', {url: '${path}/menuInfo/index_json'});
                            layer.closeAll('dialog');
                        } else if (data.code == 10002) {//系统内部错误
                            modalMsg("错误", "error");
                            window.location.href = "${path}/erroInfo/index"
                        }
                    });
            }
        });
    }

</script>

